package com.hh.demo_ui;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Toast;

import com.hh.adapters.CDTListAdapter;
import com.hh.clientdatatable.ClientDataTable;
import com.hh.clientdatatable.TCell.ValueType;
import com.hh.clientdatatable.TColumn;
import com.hh.listeners.OnHideBarListener;
import com.hh.listeners.OnNavItemsClickListener;
import com.hh.listeners.OnShowBarListener;
import com.hh.ui.widget.UiHorizontalNavBar;
import com.hh.ui.widget.UiVerticalNavBar;

public class Sample_NavigationBar extends Activity implements OnNavItemsClickListener  {

	private ClientDataTable _mCDT;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sample_navigationbar);

		createCDT();
		fillCDT();
		CDTListAdapter lAdapter=new CDTListAdapter(this, R.layout.row_horizontal_item, _mCDT){
			
			@Override
			protected void onClickRow(View row, int position) {
				super.onClickRow(row, position);
				
				String lItem=_mCDT.cellByName("Item").asString();
				Toast.makeText(Sample_NavigationBar.this, "Clicked Vertical Item : "+lItem, Toast.LENGTH_SHORT).show();
			}
		};
		
		lAdapter.setEnableOnClickWidget(false);
		/*
		 * Horizontal navigation bar
		 */
		final UiHorizontalNavBar lNavH=(UiHorizontalNavBar) findViewById(R.id.SNavBar_NavBarH);	
		lNavH.setAdapter(lAdapter);
		
		lNavH.setOnNavItemsClickListener(this);
		
		
		/*
		 * Vertical navigation bar
		 */
		
		final UiVerticalNavBar lNavV=(UiVerticalNavBar) findViewById(R.id.SNavBar_NavBarV);	
		lNavV.setAdapter(lAdapter);
		
		lNavV.setOnNavItemsClickListener(this);
		
		lNavV.setAlphaButtonRight(100);
		lNavV.setAlphaNavBar(100);
		
		lNavV.setWidth(150);
		
		lNavV.setOnShowBarListener(new OnShowBarListener() {	
			@Override
			public void onShowBar() {
				
				if(lNavH.isShowing())
					lNavH.hideBar();					
			}
		});
		
		lNavV.setOnHideBarListener(new OnHideBarListener() {		
			@Override
			public void onHideBar() {
				System.out.println("Hide VERTICAL Nav bar");	
			}
		});
		
		
		lNavH.setOnShowBarListener(new OnShowBarListener() {	
			@Override
			public void onShowBar() {
				
				if(lNavV.isShowing())
					lNavV.hideBar();					
			}
		});
		
		lNavH.setOnHideBarListener(new OnHideBarListener() {		
			@Override
			public void onHideBar() {
				System.out.println("Hide HORIZONTAL Nav bar");	
			}
		});
	}

	private void createCDT(){

		_mCDT=new ClientDataTable(this);
		_mCDT.addColumn(new TColumn("Item", ValueType.TEXT));
		_mCDT.addColumn(new TColumn("Image", ValueType.INTEGER));
	}


	private void fillCDT(){

		String[] lItemsTab=getResources().getStringArray(R.array.ArrayHorizontalItems);
		int[] lItemsImage={R.drawable.ic_chrome,R.drawable.ic_facebook,R.drawable.ic_firefox,
				R.drawable.ic_googleplus,R.drawable.ic_internet,R.drawable.ic_maps,R.drawable.ic_message,R.drawable.ic_meto,
				R.drawable.ic_plaris,R.drawable.ic_skype,R.drawable.ic_tweeter};

		for (int i = 0; i < lItemsImage.length; i++) {
			
			_mCDT.append();
			_mCDT.cellByName("Item").setValue(lItemsTab[i]);
			_mCDT.cellByName("Image").setValue(lItemsImage[i]);
			_mCDT.commit();
		}
	}

	@Override
	public void onNavItemClick(AdapterView<?> parent, View view, int position,long id) {

		_mCDT.moveToPosition(position);
		String lItem=_mCDT.cellByName("Item").asString();

		Toast.makeText(this, "Clicked Horizontal Item : "+lItem, Toast.LENGTH_SHORT).show();
		Toast.makeText(this, "Clicked Vertical Item : "+lItem, Toast.LENGTH_SHORT).show();

	}

}
